<html>
<head><meta charset="utf-8"><title>Return `false` for `needs_drop::&lt;[Box&lt;i32&gt;; 0]&gt;`? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Return.20.60false.60.20for.20.60needs_drop.3A.3A.3C.5BBox.3Ci32.3E.3B.200.5D.3E.60.3F.html">Return `false` for `needs_drop::&lt;[Box&lt;i32&gt;; 0]&gt;`?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178008382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Return%20%60false%60%20for%20%60needs_drop%3A%3A%3C%5BBox%3Ci32%3E%3B%200%5D%3E%60%3F/near/178008382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Return.20.60false.60.20for.20.60needs_drop.3A.3A.3C.5BBox.3Ci32.3E.3B.200.5D.3E.60.3F.html#178008382">(Oct 12 2019 at 22:01)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/65348" target="_blank" title="https://github.com/rust-lang/rust/issues/65348">#65348</a> is a backwards compatibility hazard with the new, dataflow-based const validator. An elegant fix for this problem (and for  <a href="https://github.com/rust-lang/rust/issues/64945" target="_blank" title="https://github.com/rust-lang/rust/issues/64945">#64945</a> as well)  would be to return <code>false</code> for the <code>needs_drop</code> query for all zero-sized arrays, regardless of the type contained within. Is this reasonable? I could duplicate the logic for<code>needs_drop</code> in <code>qualify_consts.rs</code> and make the modification there--const validation is fairly aggressive about ignoring frivolous <code>Drop</code> impls--but changing the result of the query proper might have ancillary benefits.</p>



<a name="178051765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Return%20%60false%60%20for%20%60needs_drop%3A%3A%3C%5BBox%3Ci32%3E%3B%200%5D%3E%60%3F/near/178051765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Return.20.60false.60.20for.20.60needs_drop.3A.3A.3C.5BBox.3Ci32.3E.3B.200.5D.3E.60.3F.html#178051765">(Oct 13 2019 at 19:38)</a>:</h4>
<p>See <a href="https://github.com/rust-lang/rust/issues/65389" target="_blank" title="https://github.com/rust-lang/rust/issues/65389">#65389</a>. This caused 5 codegen test failures locally due to missed optimizations when iterating over slices. I have no idea why though. The generated MIR was the same for the two that I checked, so the problem must occur when generating LLVM IR?</p>



<a name="178059013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Return%20%60false%60%20for%20%60needs_drop%3A%3A%3C%5BBox%3Ci32%3E%3B%200%5D%3E%60%3F/near/178059013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Return.20.60false.60.20for.20.60needs_drop.3A.3A.3C.5BBox.3Ci32.3E.3B.200.5D.3E.60.3F.html#178059013">(Oct 13 2019 at 23:03)</a>:</h4>
<p>I rebased on the latest master (I was on a pretty old one) and rebuilt LLVM. The problem seems to have gone away, and my PR passes CI. No idea what the root cause was.</p>



<a name="178083315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Return%20%60false%60%20for%20%60needs_drop%3A%3A%3C%5BBox%3Ci32%3E%3B%200%5D%3E%60%3F/near/178083315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Return.20.60false.60.20for.20.60needs_drop.3A.3A.3C.5BBox.3Ci32.3E.3B.200.5D.3E.60.3F.html#178083315">(Oct 14 2019 at 08:28)</a>:</h4>
<blockquote>
<p>return false for the needs_drop query for all zero-sized arrays, regardless of the type contained within. Is this reasonable?</p>
</blockquote>
<p>Why wouldn't it be? An empty array has no fields, so why would those types need drop glue ?</p>



<a name="178083332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Return%20%60false%60%20for%20%60needs_drop%3A%3A%3C%5BBox%3Ci32%3E%3B%200%5D%3E%60%3F/near/178083332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Return.20.60false.60.20for.20.60needs_drop.3A.3A.3C.5BBox.3Ci32.3E.3B.200.5D.3E.60.3F.html#178083332">(Oct 14 2019 at 08:29)</a>:</h4>
<p>In a sense, an empty array is like a <code>struct Foo&lt;T&gt;(PhantomData&lt;T&gt;);</code> which shouldn't need drop glue either for any <code>T</code> (modulo some nits, where <code>T</code> actually impacts the alignment of the array, even if it is zero-sized).</p>



<a name="178083359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Return%20%60false%60%20for%20%60needs_drop%3A%3A%3C%5BBox%3Ci32%3E%3B%200%5D%3E%60%3F/near/178083359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Return.20.60false.60.20for.20.60needs_drop.3A.3A.3C.5BBox.3Ci32.3E.3B.200.5D.3E.60.3F.html#178083359">(Oct 14 2019 at 08:29)</a>:</h4>
<p>(deleted)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>